public class SortColors {

	public void sortColors(int[] A) {
		int n = A.length, i = 0, j = n - 1, k = 0;
		while (k <= j) {
			if (A[k] == 0) {
				int tmp = A[k];
				A[k] = A[i];
				A[i] = tmp;
				i++;
			} else if (A[k] == 2) {
				int tmp = A[k];
				A[k] = A[j];
				A[j] = tmp;
				j--;
			}
			while (k <= j && (A[k] == 1 || i > k))
				k++;
		}
	}

	public static void main(String[] args) {
		SortColors a = new SortColors();
		int[] A = new int[] { 2, 0, 0 };
		a.sortColors(A);
	}

}
